package edu.upn.sigemfi.rec.bc;

import edu.upn.sigemfi.rec.be.CastigoCredito;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author Programador
 */
public class CastigoCreditoDelegate {

    private CastigoCreditoFacadeLocal local;

    public CastigoCreditoDelegate() {
        local = lookupCastigoCreditoFacade();
    }

    private CastigoCreditoFacadeLocal lookupCastigoCreditoFacade() {
        try {
            Context c = new InitialContext();
            return (CastigoCreditoFacadeLocal) c.lookup("java:comp/env/CastigoCreditoFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    public void crear(CastigoCredito CastigoCredito) throws Exception {
        try {
            local.create(CastigoCredito);
        } catch (Exception e) {
            local = lookupCastigoCreditoFacade();
            throw new Exception("Crear CastigoCredito. " + e.getMessage());
        }
    }

    public void editar(CastigoCredito CastigoCredito) throws Exception {
        try {
            local.edit(CastigoCredito);
        } catch (Exception e) {
            local = lookupCastigoCreditoFacade();
            throw new Exception("Editar CastigoCredito. " + e.getMessage());
        }
    }
    public void eliminar(CastigoCredito castigoCredito) throws Exception {
        try {
            local.remove(castigoCredito);
        } catch (Exception e) {
            local = lookupCastigoCreditoFacade();
            throw new Exception("Eliminar CastigoCredito. " + e.getMessage());
        }
    }
    public CastigoCredito buscar(long codigo) throws Exception {
        try {
            return local.find(codigo);
        } catch (Exception e) {
            local = lookupCastigoCreditoFacade();
            throw new Exception("Buscar CastigoCredito. " + e.getMessage());
        }
    }
}
